{% extends "base.jinja2" %}

{# BREADCRUMBS #}
{% block breadcrumbs %}
    {% if entity %}
        {% set groups=entity.groups %}
    {% else %}
        {% set entity=studio %}
    {% endif %}
    {% set page_title='Groups' %}
    {% include 'breadcrumb/breadcrumbs.jinja2' %}
{% endblock breadcrumbs %}

{# SIDEBAR #}
{% block sidebar %}

    {% if not entity %}
        {% set entity=studio %}
    {% endif %}

    {% include 'sidebar.jinja2' %}
{% endblock sidebar %}

{# PAGE-CONTENT #}
{% block page_content %}


    {% set page_title='Groups' %}
    {% include 'page_header.jinja2' %}

    {% if entity %}
        {% set address=request.route_path('get_entity_groups', id=entity.id) %}
    {% else %}
        {% set address=request.route_path('get_groups') %}
    {% endif %}
    {% set add_button_address='/groups/create/dialog?came_from='+ request.current_route_path() %}
    {% set list_item_type='Group' %}
    {% include 'components/data_table.jinja2' %}

{% endblock page_content %}


{# EXTRA-SCRIPTS #}
{% block extrascripts %}

    {% raw %}
    <script id="tmpl_itemThead" type="text/x-dot-template">

        <tr>
            <th>Thumbnail</th>
            <th>Group</th>
            <th>Created By</th>
            <th>Users</th>
            <th></th>
        </tr>
    </script>
    {% endraw %}

    {% raw %}
    <script id="tmpl_itemRow" type="text/x-dot-template">
        <tr>
            <td><img style='width:auto; height: 50px;'
                     class="img-thumbnail"
                     src="{{=it.thumbnail_full_path }}">
            </td>
            <td><a href='/groups/{{=it.id }}/view'>{{=it.name}}</a>
            </td>
            <td><a href='/users/{{=it.created_by_id}}/view'>{{=it.created_by_name}}</a>
            </td>
            <td>{{=it.users_count}}</td>
            <td>
                {{ if (it.update_group_action) { }}
                <a class="blue"

                   href="{{=it.update_group_action}}">
                    <i class="icon-edit bigger-130"></i>
                </a>{{ } }}

                {{ if (it.delete_group_action) { }}
                <a class="red"
                   data-target="#dialog_template"
                   data-toggle="modal"
                   data-keyboard=false
                   href="{{=it.delete_group_action}}?came_from={{=it.came_from }}">
                    <i class="icon-trash bigger-130"></i>
                </a>{{ } }}
            </td>
        </tr>
    </script>
    {% endraw %}

    <script>

        var tableParameters = {}
        var sortingParameters = [
            [0, 'asc']
        ]
        var tableDataAddress;


        {% if entity %}
            tableDataAddress = '{{request.route_path('get_entity_groups', id=entity.id) }}'

        {% else %}
            tableDataAddress = '{{ request.route_path('get_groups') }}'
        {% endif %}

        console.log('tableDataAddress' + tableDataAddress)

    </script>

{% endblock extrascripts %}
